<template>
  <el-container class="home-container">
    <el-header class="header animate__animated animate__fadeInDown">
      <img src="@/img/defaultAvatar.avif" alt="User Profile" class="header-logo animate__animated animate__pulse" />
      <el-button @click="exit" class="exit-button animate__animated animate__fadeIn" round>安全退出</el-button>
    </el-header>
    <el-container class="below-container">
      <el-aside class="aside animate__animated animate__fadeInLeft" width="100px">
        <div class="icon-container">
          <el-tooltip
            content="上传文件" placement="top" trigger="hover"  
          >
            <el-icon class="icon animate__animated animate__fadeIn" @click="navigateTo('upload')"><UploadFilled /></el-icon>
          </el-tooltip>

          <el-tooltip
            content="查询" placement="top" trigger="hover"  
          >
            <el-icon class="icon animate__animated animate__fadeIn" @click="handleSelectClick"><Search /></el-icon>
          </el-tooltip>

          <el-tooltip
            content="关于" placement="top" trigger="hover"  
          >
            <el-icon class="icon animate__animated animate__fadeIn" @click="navigateTo('about')"><Setting /></el-icon>
          </el-tooltip>
        </div>
      </el-aside>
      <el-main class="main animate__animated animate__fadeIn">
        <RouterView />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { useCookies } from '@vueuse/integrations/useCookies';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { getUserInfo } from '@/api/user';
import 'animate.css';

const currentUserName = ref("")
const cookie = useCookies()
const token = ref(null)
const router = useRouter()
token.value = cookie.get("user-token")

getUserInfo(cookie.get("user-token"))
  .then(res => {
    currentUserName.value = res.username;
  })
  .catch(err => {
    ElNotification({
            title: '获取用户信息失败！',
            type: 'warning',
        })
  })

const handleSelectClick = () => {
  if (currentUserName.value === "admin") {
    router.push('/home/select');
  } else {
    router.push('/home/userSelect');
  }
};

const exit = () => {
    cookie.remove("user-token",  { path: '/' })
    router.push("/")
}
const navigateTo = (des) => {
  router.push(`/home/${des}`)
}
</script>

<style scoped>
.home-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  background: linear-gradient(120deg, #1a73e8 0%, #4285f4 100%);
  height: 60px;
  line-height: 60px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.header-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 10px;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.exit-button {
  background: linear-gradient(120deg, #1a73e8 0%, #4285f4 100%);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(5px);
  transition: all 0.3s ease;
}

.exit-button:hover {
  background: linear-gradient(120deg, #d93025 0%, #ea4335 100%);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(217, 48, 37, 0.4);
}

.below-container {
  display: flex;
  flex: 1;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

.aside {
  background: linear-gradient(180deg, #1a73e8 0%, #4285f4 100%);
  padding: 10px;
  text-align: center;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.main {
  flex: 1;
  background-color: rgba(255, 255, 255, 0.9);
  padding: 20px;
  overflow: auto;
  border-radius: 10px;
  margin: 10px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
}

.icon-container {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  height: 100%;
}

.icon {
  color: rgba(255, 255, 255, 0.9);
  font-size: 36px;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
}

.icon:hover {
  transform: scale(1.2) rotate(5deg);
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}
</style>